package com.zzptc.ly.a12_14.adater;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.zzptc.ly.a12_14.R;
import com.zzptc.ly.a12_14.databinding.RvItemBinding;
import com.zzptc.ly.a12_14.entity.RecipeModel;

import java.util.List;

public class MyRecipteAdpter extends RecyclerView.Adapter<MyRecipteAdpter.ViewHolder> {
    private List<RecipeModel.ResultsBean> list;
    private Context context;

    public MyRecipteAdpter(List<RecipeModel.ResultsBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        RvItemBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),
                R.layout.rv_item,parent,false);
        return new ViewHolder(binding);
    }
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        //    数据在哪？list
        int position1 = position;
        RecipeModel.ResultsBean resultsBean = list.get(position1);
        holder.rvItemBinding.tvTitle.setText(resultsBean.getTitle());
//        holder.rvItemBinding.ivPic.setImageResource();
        Glide.with(context)
                .load(resultsBean.getCover())
                .into(holder.rvItemBinding.ivPic);

    }
    @Override
    public int getItemCount() {
        return list.size();
    }
        public class ViewHolder extends RecyclerView.ViewHolder {
        private RvItemBinding rvItemBinding;
        public ViewHolder(@NonNull RvItemBinding rvItemBinding) {
            super(rvItemBinding.getRoot());
            this.rvItemBinding=rvItemBinding;
        }
    }
}
